import pandas as pd
from LSTM.variableset import EMVar, EMPath
import numpy as np
from emutils import series_utils,draw_utils,stk_utils
import matplotlib.pyplot as plt
import matplotlib
import tushare as ts

import time
from em_logger import logger as el


is_plot_his = False
is_stage_classify = False
is_predict_buy_sta = True
is_plot_predict_buy = False
is_sta_offset_result = False
is_sta_index = False

total_profit_except = 0


total_predict_buy = []

def result_list_detect(stk_list=None):
    if isinstance(stk_list, list):
        for code in stk_list:
            detect(code=code)
        if len(total_predict_buy)>0:
            total_buy_df = pd.concat(total_predict_buy,ignore_index=True)
            total_buy_df.sort_values(EMVar.dp1_date, inplace=True)
            total_buy_df.to_csv(path_or_buf=EMPath.data_file_full_path(is_common=True, fileName='total_buy.csv'))


def classify(dataframe, column_name):
    dataframe['tmp'] = dataframe[column_name].copy()
    dataframe.loc[:, 'tmp'][dataframe[column_name] > 0.1] = 10
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= 0.1) & (dataframe[column_name] > 0.05)] = 5
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= 0.05) & (dataframe[column_name] > 0.03)] = 3
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= 0.03) & (dataframe[column_name] > 0)] = 1
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= 0.0) & (dataframe[column_name] > -0.03)] = -1
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= -0.03) & (dataframe[column_name] > -0.05)] = -3
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= -0.05) & (dataframe[column_name] > -0.1)] = -5
    dataframe.loc[:, 'tmp'][(dataframe[column_name] <= -0.1)] = -10
    return dataframe['tmp']


def detect(code=EMVar.TEST_STOCK):
    matplotlib.matplotlib_fname()
    sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])

    result_file = EMPath.data_file_full_path(code=code, fileName='result_' + code + '.csv')


    df = pd.read_csv(open(result_file))

    df = df[((df['real'] != 0) | (df['predict'] != 0) | (df['acc'] != 0)) & (df['acc'] != np.inf)]
    # .abs()

    acc = df[EMVar.acc]
    x, y, mean, std = series_utils.normfun(acc)
    el.debug('%s 预测误差平均值:%f, 预测误差的方差:%f'%(code, mean, std))
    if is_plot_his:
        plt.plot(x, y, color='g', linewidth=3)
        # 数据，数组，颜色，颜色深浅，组宽，显示频率
        plt.hist(acc, bins=100, color='r', alpha=0.5, rwidth=0.9, normed=True)
        plt.title(u'内容')
        plt.xlabel(u'偏差值')
        plt.ylabel(u'偏差值分布')
        plt.show()


    sta_index = 'sta_index'
    acc_sta_index = 'acc_sta_index'

    df[sta_index] = (((df[EMVar.close] <= df[EMVar.real]) & (df[EMVar.close] <= df[EMVar.predict])) | (
        (df[EMVar.close] >= df[EMVar.real]) & (df[EMVar.close] >= df[EMVar.predict])) | (
                         (np.abs(df[EMVar.acc]) < 0.01)))

    all_true_count, all_fall_count, all_total_count = series_utils.column_true_false_count(df[sta_index])

    # acc 是 预测值 - 实际 / 预测
    # 统计基本数据
    df[acc_sta_index] = df[EMVar.acc] >= 0
    acc_true_count, acc_false_count, acc_all_count = series_utils.column_true_false_count(df[acc_sta_index])
    acc_sta_str_info = '%s 成功数据%d条，失败数据%d条，一共%d条\n成功率:%f' % (
        code, all_true_count, all_fall_count, all_total_count, (float(all_true_count) / all_total_count))
    el.debug(acc_sta_str_info)
    sta_count_info = '%s 预测值较大的数据%d条，真实值较大的数据%d条，一共%d条' % (code, acc_true_count, acc_false_count, acc_all_count)
    el.debug(sta_count_info)

    # 统计阶段涨跌幅
    if is_stage_classify:
        real_ajx_price = 'real_ajx_price'
        predict_ajx_price = 'predict_ajx_price'
        real_ajx_price_stage = 'real_ajx_price_stage'
        predict_ajx_price_stage = 'predict_ajx_price_stage'
        df[real_ajx_price] = (df[EMVar.real] - df[EMVar.close]) / df[EMVar.close]
        df[predict_ajx_price] = (df[EMVar.predict] - df[EMVar.close]) / df[EMVar.close]
        df[real_ajx_price_stage] = classify(df, real_ajx_price)
        df[predict_ajx_price_stage] = classify(df, predict_ajx_price)
        stage_sta_index = 'stage_sta_index'
        df[stage_sta_index] = (df[real_ajx_price_stage] == df[predict_ajx_price_stage])
        stage_true_count, stage_false_count, stage_all_count = series_utils.column_true_false_count(df[stage_sta_index])
        stage_sta_info = '%s 涨跌幅级别统计正确数据%d条，涨跌幅级别统计不正确数据%d条，一共%d条,准确率%f' % (code,stage_true_count, stage_false_count, stage_all_count,stage_true_count/stage_all_count)
        el.debug(stage_sta_info)
        _, stage_continuous_sta_info = series_utils.cout_continuous_data(df[stage_sta_index],{True: code+'涨跌幅级别统计正确', False: code+'涨跌幅级别统计错误'})



    if is_predict_buy_sta:
        # predict_buy_sta(df=df, code=code)
        predict_buy_sta_offset(df=df, code=code,offset=-10)
        pass



    # ,
    # columns = EMVar.PREDICT_FILE_COLUMNS + [sta_index, real_ajx_price, real_ajx_price_stage,
    #                                         predict_ajx_price, predict_ajx_price_stage]
    el.debug('\n\n###########################华丽分割###############################################\n\n')

    # EMVar.save_env({'成功/失败统计信息': acc_sta_str_info,
    #                 '预测/实际大小比较统计信息:': sta_count_info,
    #                 '涨跌幅级别统计信息': stage_sta_info,
    #                 '连续性统计信息:': stage_continuous_sta_info})




def predict_buy_sta_offset(df=None, code=None, offset=-1, min_offset=-30):
    if offset >= -1:
        offset = -1
    if offset <= min_offset:
        offset = min_offset
    buy_field = EMVar.predictMin
    out_detect_file = EMPath.data_file_full_path(code=code, fileName=(EMVar.DETECT_FILE_PREFIX + code + '.csv'))

    df[EMVar.code] = code
    df[EMVar.dp1_close] = series_utils.data_offset(df[EMVar.close], offset=-1, fill_value=0)
    df[EMVar.dp1_open] = series_utils.data_offset(df[EMVar.open], offset=-1, fill_value=0)
    df[EMVar.dp1_high] = series_utils.data_offset(df[EMVar.high], offset=-1, fill_value=0)
    df[EMVar.dp1_low] = series_utils.data_offset(df[EMVar.low], offset=-1, fill_value=0)
    df[EMVar.dp1_date]= series_utils.data_offset(df[EMVar.date], offset=-1, fill_value=np.NAN)

    field_close_max = 'max_dp' + str(abs(offset)) + '_close'
    field_open_max = 'max_dp' + str(abs(offset)) + '_open'
    field_high_max = 'max_dp' + str(abs(offset)) + '_high'
    field_low_min = 'min_dp' + str(abs(offset)) + '_low'
    df[field_close_max], _= series_utils.describe_data_offset(df[EMVar.close], cal_max=True, offset=offset)
    df[field_open_max], _ = series_utils.describe_data_offset(df[EMVar.open],cal_max=True, offset=offset)
    df[field_high_max], _ = series_utils.describe_data_offset(df[EMVar.high],cal_max=True, offset=offset)
    _, df[field_low_min] = series_utils.describe_data_offset(df[EMVar.low],cal_min=True, offset=offset)

    df = df[np.isfinite(df[field_close_max]) & np.isfinite(df[field_open_max]) & np.isfinite(df[field_high_max]) & np.isfinite(df[field_low_min]) ]
    df.to_csv(path_or_buf=out_detect_file, index=False)

    # 最低值不能高于预测值, 因为标准是以预测值进行买入，所以 如果最小值高于预测值，则后面判断成功的价格不是预测值，而是最小值(就是买入价格)
    buy_offset = -0.02
    thred = 0.005
    compare_field = EMVar.dp1_low
    profit_set = 0.025 if abs(buy_offset) < 0.03 else abs(buy_offset)

    times = 0
    l = range(-60, 0, 5)
    df_faile_pieces = []
    df_success_pieces = []
    for i in l:
        times += 1
        if is_sta_offset_result:
            buy_offset = i / 1000
            top = buy_offset + thred
        else:
            if times == 1:
                buy_offset = -100
                top = 0
            else:
                break
        el.info('\n\n##################\n\n')
        # (buy_offset < ((df[compare_field] - df[buy_field]) / df[buy_field])) &
        df['predict_min_buy'] = (((df[compare_field] - df[buy_field]) / df[buy_field]) <= top)
        # df['predict_min_success'] =  (df[EMVar.tomorrow_close]>=df[buy_field])
        tmpdf = df[df['predict_min_buy']]
        total_predict_buy.append(tmpdf)
        if not tmpdf.empty:
            # price_offset = (buy_offset + top) / 2
            price_offset = top
            tmpdf.loc[:, 'predict_min_acc'] = (df[field_high_max] - df[buy_field] * (1 + price_offset)) / df[buy_field]
            tmpdf.loc[:, 'predict_min_low_acc'] = (df[field_low_min] - df[buy_field] * (1 + price_offset)) / df[buy_field]
            tmpdf.loc[:, 'predict_min_success'] = tmpdf['predict_min_acc'] >= profit_set
            # tmpdf['predict_min_success'] = (df[EMVar.dp2_high] >= df[buy_field])
            stage_true_count, stage_false_count, stage_all_count = series_utils.column_true_false_count(
                tmpdf['predict_min_success'])
            stage_sta_info = '%s涨跌幅偏移预测正确数据%d条，涨跌幅偏移预测不正确数据%d条，一共%d条,区间 [%s -- %s] 准确率%f' % (
                code, stage_true_count, stage_false_count, stage_all_count, buy_offset, top,stage_true_count / stage_all_count)
            el.info(stage_sta_info)
            tmp_file_path = EMPath.data_file_full_path(code=code, fileName=('tmp_' + code + '.csv'))
            tmpdf = tmpdf[tmpdf['predict_min_acc'] != -1]
            predict_faile_df = tmpdf[(tmpdf['predict_min_success'] == False)]
            if not predict_faile_df.empty:
                faile_acc = np.average(predict_faile_df['predict_min_acc'].tolist())
                faile_low_acc = np.average(predict_faile_df['predict_min_low_acc'].tolist())
                df_faile_pieces.append(predict_faile_df)
            else:
                faile_acc = 0
                faile_low_acc = 0
            el.info('%s涨跌幅预测错误时最高值与买入价差为:%f，最低值与买入价差为:%f' % (code, faile_acc, faile_low_acc))
            predict_success_df = tmpdf[(tmpdf['predict_min_success'] == True)]
            if not predict_success_df.empty:
                success_acc = np.average(predict_success_df['predict_min_acc'].tolist())
                success_low_acc = np.average(predict_success_df['predict_min_low_acc'].tolist())
                df_success_pieces.append(predict_success_df)
            else:
                success_acc = 0
                success_low_acc = 0
            el.info('%s涨跌幅预测正确时最高值与买入价差为:%f，最低值与买入价差为:%f' % (code, success_acc, success_low_acc))
            stage_success_pct = stage_true_count / stage_all_count
            profit_except = faile_acc * (1 - stage_success_pct) + success_acc * stage_success_pct
            global total_profit_except
            el.info('❤❤❤❤%s, 统计区间 %s -- %s,目标:%.2f%%,收益期望为:%f❤❤❤❤' % (
            code, buy_offset, top, profit_set * 100, profit_except))
            total_profit_except += profit_except
            tmpdf.to_csv(path_or_buf=tmp_file_path)

            _, stage_continuous_sta_info = series_utils.cout_continuous_data(tmpdf['predict_min_success'],
                                                                             {True: '涨跌幅偏移预测统计正确',
                                                                              False: '涨跌幅偏移预测统计错误'})

            m = 0
            tmpDic = tmpdf.to_dict(orient='index')
            if is_plot_predict_buy:
                # 换一只 先挂个60秒
                if m != 0:
                    time.sleep(60)
                for key, item in tmpDic.items():
                    try:
                        # if m == 1:
                        #     break

                        # 因为预测是明天的情况，所以需要拿到明天的tick值才对，也就是预测False 其实是明天的tick计算结果为false
                        m = m + 1
                        # cur_date 是 收盘后进行预测的日期
                        cure_date = item[EMVar.date]
                        # price 是 当明天低于这个价格的时候进行买入
                        sum_last_predict = item[EMVar.sumAcc_least_predict]
                        second_last_predict = item[EMVar.secondLastAcc_least_predict]
                        price = item[buy_field]

                        # dp1 是 买入的日期
                        dp1 = df.at[key + 1, EMVar.date]

                        # data = None
                        # dm_datas = None
                        # dp_datas = None
                        data = stk_utils.em_get_tick_data(code=code, date=dp1)
                        dm_datas, dp_datas = stk_utils.em_get_tick_data_offset(code=code, date=dp1, date_index_list=df[EMVar.date].tolist(), pre_offset=-1, later_offset=10)

                        # 取前后10天大盘数据
                        date_l, _ = stk_utils.em_get_date_offset(date=dp1, date_index_list=df[EMVar.date].tolist(),pre_offset=-10, later_offset=10)
                        fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
                        stk_his_data = stk_utils.em_get_h_data(code=code, index=False, start=date_l[0], end=date_l[-1])
                        sh_his_data = stk_utils.em_get_h_data(code=EMVar.CODE_SH, index=True, start=date_l[0], end=date_l[-1])
                        zx_his_data = stk_utils.em_get_h_data(code=EMVar.CODE_ZX, index=True, start=date_l[0], end=date_l[-1])

                        draw_utils.draw_day_k(stk_his_data, ax=ax2, title=code+'日线')
                        draw_utils.draw_day_k(sh_his_data, ax=ax3, title='上证日线')
                        draw_utils.draw_day_k(zx_his_data, ax=ax4, title='中小日线')

                        if not item['predict_min_success']:
                            save_path = EMPath.data_root_path(is_common=True) + dp1 + '_' + code + '_F' + '.png'
                            draw_utils.draw_tick_datas(datas=dm_datas+[data]+dp_datas, save_path=save_path,
                                                       ax=ax1,
                                                       is_show=False,
                                                       hlines=[{'y': price, 'color': 'green', 'style': ':'},
                                                               {'y': sum_last_predict, 'color': 'gray'},
                                                               {'y': second_last_predict, 'color': 'pink'}])
                            plt.close()

                        else:
                            save_path = EMPath.data_root_path(is_common=True) + dp1 + '_' + code + '_S' + '.png'
                            draw_utils.draw_tick_datas(datas=dm_datas+[data]+dp_datas, save_path=save_path,
                                                       ax=ax1,
                                                       is_show=False,
                                                       hlines=[{'y': price, 'color': 'red', 'style': ':'},
                                                               {'y': sum_last_predict, 'color': 'gray'},
                                                               {'y': second_last_predict, 'color': 'pink'}])
                            plt.close()

                    except Exception as e:
                        el.debug(e)
                        print(e)
                        continue

            if is_sta_index:
                for key, item in tmpDic.items():
                    cur_date = item[EMVar.date]

                    if not item['predict_min_success']:
                        pass
                    else:
                        pass

        else:
            el.info('❤❤❤❤%s,统计区间%s -- %s , 区间无数据❤❤❤❤' % (code, buy_offset, top))


        el.info('\n\n######统计分割线######\n\n')

        if i == list(l)[-1]:
            df_success_sta = pd.concat(df_success_pieces)
            df_faile_sta = pd.concat(df_faile_pieces)
            total_success_pct = df_success_sta.shape[0] / (df_success_sta.shape[0] + df_faile_sta.shape[0])
            el.info('%s 整体统计 正确 %d条，错误%d条，正确率 %f' % (
            code, df_success_sta.shape[0], df_faile_sta.shape[0], total_success_pct))
            pass



def predict_buy_sta(df=None, code=None):
    buy_field = EMVar.predictMin
    out_detect_file = EMPath.data_file_full_path(code=code, fileName=(EMVar.DETECT_FILE_PREFIX + code + '.csv'))

    df[EMVar.dp1_close] = series_utils.data_offset(df[EMVar.close], offset=-1, fill_value=0)
    df[EMVar.dp1_open] = series_utils.data_offset(df[EMVar.open], offset=-1, fill_value=0)
    df[EMVar.dp1_high] = series_utils.data_offset(df[EMVar.high], offset=-1, fill_value=0)
    df[EMVar.dp1_low] = series_utils.data_offset(df[EMVar.low], offset=-1, fill_value=0)

    df[EMVar.dp2_close] = series_utils.data_offset(df[EMVar.close], offset=-2, fill_value=0)
    df[EMVar.dp2_high] = series_utils.data_offset(df[EMVar.high], offset=-2, fill_value=0)
    df[EMVar.dp2_low] = series_utils.data_offset(df[EMVar.low], offset=-2, fill_value=0)

    df.to_csv(path_or_buf=out_detect_file, index=False)

    # 最低值不能高于预测值, 因为标准是以预测值进行买入，所以 如果最小值高于预测值，则后面判断成功的价格不是预测值，而是最小值(就是买入价格)
    buy_offset = -0.02
    thred = 0.005
    compare_field = EMVar.dp1_low
    profit_set = 0.02 if abs(buy_offset) < 0.03 else abs(buy_offset)

    times = 0
    l = range(-60, 0, 5)
    df_faile_pieces = []
    df_success_pieces = []
    for i in l:
        times += 1
        if is_sta_offset_result:
            buy_offset = i / 1000
            top = buy_offset + thred
        else:
            if times == 1:
                buy_offset = -100
                top = -0.025
            else:
                break
        el.info('\n\n##################\n\n')
        # (buy_offset < ((df[compare_field] - df[buy_field]) / df[buy_field])) &
        df['predict_min_buy'] = (((df[compare_field] - df[buy_field]) / df[buy_field]) <= top)
        # df['predict_min_success'] =  (df[EMVar.tomorrow_close]>=df[buy_field])
        tmpdf = df[df['predict_min_buy']]
        if not tmpdf.empty:
            # price_offset = (buy_offset + top) / 2
            price_offset = top
            tmpdf.loc[:, 'predict_min_acc'] = (df[EMVar.dp2_high] - df[buy_field] * (1 + price_offset)) / df[buy_field]
            tmpdf.loc[:, 'predict_min_low_acc'] = (df[EMVar.dp2_low] - df[buy_field] * (1 + price_offset)) / df[
                buy_field]
            tmpdf.loc[:, 'predict_min_success'] = tmpdf['predict_min_acc'] >= profit_set
            # tmpdf['predict_min_success'] = (df[EMVar.dp2_high] >= df[buy_field])
            stage_true_count, stage_false_count, stage_all_count = series_utils.column_true_false_count(
                tmpdf['predict_min_success'])
            stage_sta_info = '%s涨跌幅偏移预测正确数据%d条，涨跌幅偏移预测不正确数据%d条，一共%d条,区间 [%s -- %s] 准确率%f' % (
                code, stage_true_count, stage_false_count, stage_all_count, buy_offset, top,
                stage_true_count / stage_all_count)
            el.info(stage_sta_info)
            tmp_file_path = EMPath.data_file_full_path(code=code, fileName=('tmp_' + code + '.csv'))
            tmpdf = tmpdf[tmpdf['predict_min_acc'] != -1]
            predict_faile_df = tmpdf[(tmpdf['predict_min_success'] == False)]
            if not predict_faile_df.empty:
                faile_acc = np.average(predict_faile_df['predict_min_acc'].tolist())
                faile_low_acc = np.average(predict_faile_df['predict_min_low_acc'].tolist())
                df_faile_pieces.append(predict_faile_df)
            else:
                faile_acc = 0
                faile_low_acc = 0
            el.info('%s涨跌幅预测错误时最高值与买入价差为:%f，最低值与买入价差为:%f' % (code, faile_acc, faile_low_acc))
            predict_success_df = tmpdf[(tmpdf['predict_min_success'] == True)]
            if not predict_success_df.empty:
                success_acc = np.average(predict_success_df['predict_min_acc'].tolist())
                success_low_acc = np.average(predict_success_df['predict_min_low_acc'].tolist())
                df_success_pieces.append(predict_success_df)
            else:
                success_acc = 0
                success_low_acc = 0
            el.info('%s涨跌幅预测正确时最高值与买入价差为:%f，最低值与买入价差为:%f' % (code, success_acc, success_low_acc))
            stage_success_pct = stage_true_count / stage_all_count
            profit_except = faile_acc * (1 - stage_success_pct) + success_acc * stage_success_pct
            global total_profit_except
            el.info('❤❤❤❤%s, 统计区间 %s -- %s,目标:%.2f%%,收益期望为:%f❤❤❤❤' % (
            code, buy_offset, top, profit_set * 100, profit_except))
            total_profit_except += profit_except
            tmpdf.to_csv(path_or_buf=tmp_file_path)

            _, stage_continuous_sta_info = series_utils.cout_continuous_data(tmpdf['predict_min_success'],
                                                                             {True: '涨跌幅偏移预测统计正确',
                                                                              False: '涨跌幅偏移预测统计错误'})

            m = 0
            tmpDic = tmpdf.to_dict(orient='index')
            if is_plot_predict_buy:
                # 换一只 先挂个60秒
                if m != 0:
                    time.sleep(60)
                for key, item in tmpDic.items():
                    # 因为预测是明天的情况，所以需要拿到明天的tick值才对，也就是预测False 其实是明天的tick计算结果为false
                    if (key + 1 not in df.index.tolist()) or (key + 2 not in df.index.tolist()) or (
                                    key - 1 not in df.index.tolist()):
                        continue
                    m = m + 1
                    # cur_date 是 收盘后进行预测的日期
                    cure_date = item[EMVar.date]
                    # price 是 当明天低于这个价格的时候进行买入
                    sum_last_predict = item[EMVar.sumAcc_least_predict]
                    second_last_predict = item[EMVar.secondLastAcc_least_predict]
                    price = item[buy_field]

                    # dp1 是 买入的日期
                    dp1 = df.at[key + 1, EMVar.date]
                    # dp2 是 研究买入后1天的情况
                    dp2 = df.at[key + 2, EMVar.date]
                    # dm1 是 研究买入前1天的情况
                    dm1 = df.at[key - 1, EMVar.date]
                    el.debug('key : %d , curDate: %s predictDate: %s' % (key, cure_date, dp1))
                    data = stk_utils.em_get_tick_data(code=code, date=dp1)
                    dp2_data = stk_utils.em_get_tick_data(code=code, date=dp2)
                    dm1_data = stk_utils.em_get_tick_data(code=code, date=dm1)
                    if not item['predict_min_success']:
                        save_path = EMPath.data_root_path(is_common=True) + dp1 + '_' + code + '_F' + '.png'
                        draw_utils.draw_tick_datas(datas=[dm1_data, data, dp2_data], save_path=save_path,
                                                   is_show=False,
                                                   hlines=[{'y': price, 'color': 'green', 'style': ':'},
                                                           {'y': sum_last_predict, 'color': 'gray'},
                                                           {'y': second_last_predict, 'color': 'pink'}])
                    else:
                        save_path = EMPath.data_root_path(is_common=True) + dp1 + '_' + code + '_S' + '.png'
                        draw_utils.draw_tick_datas(datas=[dm1_data, data, dp2_data], save_path=save_path,
                                                   is_show=False,
                                                   hlines=[{'y': price, 'color': 'red', 'style': ':'},
                                                           {'y': sum_last_predict, 'color': 'gray'},
                                                           {'y': second_last_predict, 'color': 'pink'}])

        else:
            el.info('❤❤❤❤%s,统计区间%s -- %s , 区间无数据❤❤❤❤' % (code, buy_offset, top))
        el.info('\n\n######统计分割线######\n\n')

        if i == list(l)[-1]:
            df_success_sta = pd.concat(df_success_pieces)
            df_faile_sta = pd.concat(df_faile_pieces)
            total_success_pct = df_success_sta.shape[0] / (df_success_sta.shape[0] + df_faile_sta.shape[0])
            el.info('%s 整体统计 正确 %d条，错误%d条，正确率 %f' % (
            code, df_success_sta.shape[0], df_faile_sta.shape[0], total_success_pct))
            pass


result_list_detect(stk_list=EMVar.DATA_SOURCE_LIST)

if is_predict_buy_sta:
    el.debug('总体收益期望为: %f'%(total_profit_except/len(EMVar.DATA_SOURCE_LIST)))
